package com.itheima.jdk8date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class Test01 {

    public static void main(String[] args) throws ParseException {
       // jdk7();
        //jdk8
        String s="2021-04-25 10:46:15";
        //转换对象
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateTime = LocalDateTime.parse(s, formatter);
        LocalDateTime newDateTime = dateTime.plusDays(1);
        String format = newDateTime.format(formatter);
        System.out.println(format);

    }

    public static void jdk7() throws ParseException {
        //jdk7
        String s="2021-04-25 10:46:15";
        //转日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //转毫秒值
        long time = sdf.parse(s).getTime();
        //+一天的毫秒值
        time=time+1000*60*60*24;
        //设置到新的日期对象中
        Date newDate = new Date(time);
        //日期转 字符串
        String newS = sdf.format(newDate);
        System.out.println(newS);
    }
}
